package ioc15;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class PostProcessBean implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof SomeBean)
        {
            SomeBean someBean = (SomeBean) bean;
            someBean.setName(someBean.getName().toUpperCase());
        }

        if (bean instanceof OtherBean)
        {
            OtherBean otherBean = (OtherBean) bean;
            String name = otherBean.getName();
            String s = String.valueOf(name.charAt(0));
            String s1 = s.toUpperCase();
            String substring = name.substring(1);
            String s2 = substring.toLowerCase();
            otherBean.setName(s1+s2);

        }
        return bean;

    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return null;
    }
}
